package com.example.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.concurrent.locks.LockSupport;

@Service
@Slf4j
public class LockSupportExampleService {

    private Thread parkedThread;

    public void parkThread() {
        parkedThread = Thread.currentThread();
        log.info("线程 [{}] 将被挂起", parkedThread.getName());
        LockSupport.park();
        log.info("线程 [{}] 已被唤醒", parkedThread.getName());
    }

    public void unparkThread() {
        if (parkedThread != null) {
            log.info("唤醒线程 [{}]", parkedThread.getName());
            LockSupport.unpark(parkedThread);
        }
    }
}
